﻿using System;
using System.Windows;

namespace RemoteDesktop
{
    /// <summary>
    /// App.xaml 的交互逻辑
    /// </summary>
    public partial class App : Application
    {
        public App()
        {
            //UI线程异常
            this.DispatcherUnhandledException += App_DispatcherUnhandledException;
            //非UI线程异常
            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
        }
        private void App_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
        {
            //可以记录日志并转向错误bug窗口友好提示用户
            e.Handled = true;
            try
            {
                PLogs.Error(e.Exception.StackTrace.ToString(), e.Exception.Message);

            }
            catch (Exception)
            {


            }
            MessageBox.Show("抱歉给您带来不便！消息:" + e.Exception.Message, "系统错误", MessageBoxButton.OK, MessageBoxImage.Error);

        }
        private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
        {
            //可以记录日志并转向错误bug窗口友好提示用户
            if (e.ExceptionObject is System.Exception)
            {

                Exception ex = (System.Exception)e.ExceptionObject;
                try
                {
                    PLogs.Error(ex.StackTrace.ToString(), ex.Message);

                }
                catch (Exception)
                {


                }
                MessageBox.Show("抱歉给您带来不便！消息:" + ex.Message, "系统错误", MessageBoxButton.OK, MessageBoxImage.Error);

            }
        }
    }
}
